package com.java.al.map;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

/**
 * @author 橙子
 * 迭代取出Map 的key 和value 值
 */
public class MapIterator {
	
	public static void iteratorMapKey(Map<String,String> map){
		Set<String> set = map.keySet();
		for(Iterator<String> it = set.iterator();it.hasNext();){
			String key = (String) it.next();
			String value = map.get(key);
			System.out.println("key:"+key+"\t value:"+value);
		}
	}
	
	/**
	 * 这个方式 忘了怎么得 key了~~
	 * @param map
	 */
	public static void iteratorMapValues(Map<String,String> map){
		Collection<String> coll = map.values();
		for(Iterator<String> it = coll.iterator();it.hasNext();){
			String value = it.next();
			System.out.println("key:忘了怎么得key了\t value:"+value);
		}
	}
	
	public static void iteratorMapEntrty(Map<String,String> map){
		Set<Entry<String, String>> entrySet= map.entrySet();
		for(Iterator<Entry<String, String>> it = entrySet.iterator();it.hasNext();){
			Entry<String, String> entry = it.next();
			String key = entry.getKey();
			String value = entry.getValue();
			System.out.println("key:"+key+"\t value:"+value);
		}
	}
	
}
